package com.ruoyi.project.beautyflower.loanPurpose.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.loanPurpose.domain.LoanPurpose;
import com.ruoyi.project.beautyflower.loanPurpose.service.ILoanPurposeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 借款用途设置 信息操作处理
 * 
 * @author lxs
 * @date 2018-10-09
 */
@Controller
@RequestMapping("/beautyflower/loanPurpose")
public class LoanPurposeController extends BaseController
{
    private String prefix = "beautyflower/loanPurpose";
	
	@Autowired
	private ILoanPurposeService loanPurposeService;
	
	@RequiresPermissions("beautyflower:loanPurpose:view")
	@GetMapping()
	public String loanPurpose()
	{
	    return prefix + "/loanPurpose";
	}
	
	/**
	 * 查询借款用途设置列表
	 */
	@RequiresPermissions("beautyflower:loanPurpose:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(LoanPurpose loanPurpose)
	{
		startPage();
        List<LoanPurpose> list = loanPurposeService.selectLoanPurposeList(loanPurpose);
		return getDataTable(list);
	}
	
	/**
	 * 新增借款用途设置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存借款用途设置
	 */
	@RequiresPermissions("beautyflower:loanPurpose:add")
	@Log(title = "借款用途设置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(LoanPurpose loanPurpose)
	{		
		return toAjax(loanPurposeService.insertLoanPurpose(loanPurpose));
	}

	/**
	 * 修改借款用途设置
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		LoanPurpose loanPurpose = loanPurposeService.selectLoanPurposeById(id);
		mmap.put("loanPurpose", loanPurpose);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存借款用途设置
	 */
	@RequiresPermissions("beautyflower:loanPurpose:edit")
	@Log(title = "借款用途设置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(LoanPurpose loanPurpose)
	{		
		return toAjax(loanPurposeService.updateLoanPurpose(loanPurpose));
	}
	
	/**
	 * 删除借款用途设置
	 */
	@RequiresPermissions("beautyflower:loanPurpose:remove")
	@Log(title = "借款用途设置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(loanPurposeService.deleteLoanPurposeByIds(ids));
	}
	
}
